from ghmm import HMMOpen, Alphabet, SequenceSet
from bsmart import BSmart
from random import uniform

#save some generated sequences...
l=['a','b','c','d','e','f','g','h','i','l']
a=Alphabet(l)
sequences_for_model = 50
m0=HMMOpen("./models/model0.xml")
m1=HMMOpen("./models/model1.xml")
m2=HMMOpen("./models/model2.xml")
m3=HMMOpen("./models/model3.xml")
probFile = file("./models/probabilities.txt", 'r')
lines = probFile.readlines()
prob = []
for line in lines:
    prob.append(float(line.split()[1]))
probFile.close()
bs = BSmart(l)
bs.addModel(m0)
bs.addModel(m1)
bs.addModel(m2)
bs.addModel(m3)
for i in range(len(prob)):
    bs.addModelProbability(i, prob[i])   
    

seqM0= []
for i in range(sequences_for_model):
    seqM0.append(map(a.external, m0.sampleSingle(int(uniform(10,50)))))

seqM1= []
for i in range(sequences_for_model):
    seqM1.append(map(a.external, m1.sampleSingle(int(uniform(10,50)))))

seqM2= []
for i in range(sequences_for_model):
    seqM2.append(map(a.external, m2.sampleSingle(int(uniform(10,50)))))

seqM3= []
for i in range(sequences_for_model):
    seqM3.append(map(a.external, m3.sampleSingle(int(uniform(10,50)))))

s0=SequenceSet(a,seqM0)
s1=SequenceSet(a,seqM1)
s2=SequenceSet(a,seqM2)
s3=SequenceSet(a,seqM3)
s0.write("./models/sequencesStep1.txt")
s1.write("./models/sequencesStep1.txt")
s2.write("./models/sequencesStep1.txt")
s3.write("./models/sequencesStep1.txt")



seqAll= [[],[],[],[]]
for i in range(sequences_for_model*8):
    ret = bs.produceVerbose(int(uniform(10,50)))
    seqAll[ret[1]].append(ret[0])


for i in seqAll:
    SequenceSet(a,i).write("./models/sequencesStep2.txt")
